<template>
  <div class="page">
    <el-form ref="form" :rules="rules" :model="form" class="form">
      <el-form-item label="身份证号" prop="idcard">
        <el-input v-model="form.idcard" placeholder="请输入身份证号"></el-input>
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入手机号码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="changePhone">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { changePhone } from '@/api/official/official'
export default {
  name: 'InternetHospitalMangeChangePhone',

  data() {
    return {
      loading: false,
      rules: {
        idcard: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ]
      },
      form: {}
    };
  },

  mounted() {
    
  },

  methods: {
    changePhone() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true;
          changePhone(this.form).then(res => {
            this.loading = false;
            this.$message[res === '修改成功' ? 'success' : 'error'](res);
            this.$emit('changePhone');
          }).catch(err => {
            this.loading = false;
          });
        } else {
          console.log('error submit!!');
          return false;
        }
        
      })
      
    }
  },
};
</script>

<style>
.page {
  padding: 24px;
}
.form {
  width: 500px;
  margin: 20px auto;
}
</style>